using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region QuestionType

	/// <summary>
	/// QuestionType object for NHibernate mapped table 'QuestionType'.
	/// </summary>
	public class QuestionType : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _questionTypeName;
		protected IList _surveyQuestionses;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public QuestionType() { }

		public QuestionType( string questionTypeName )
		{
			this._questionTypeName = questionTypeName;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string QuestionTypeName
		{
			get { return _questionTypeName; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_questionTypeName = value;
			}
		}

		public IList SurveyQuestionses
		{
			get
			{
				if (_surveyQuestionses==null)
				{
					_surveyQuestionses = new ArrayList();
				}
				return _surveyQuestionses;
			}
			set { _surveyQuestionses = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is QuestionType))
				throw new InvalidCastException("This object is not of type QuestionType");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((QuestionType)obj).Id);
					break;
				case "QuestionTypeName":
						relativeValue = ( this.QuestionTypeName != null ) ? this.QuestionTypeName.CompareTo(((QuestionType)obj).QuestionTypeName) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (QuestionType.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
